package cn.edu.lit.jsjxy.CourseExample.chapter5;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import cn.edu.lit.jsjxy.CourseExample.R;

public class MusicReceiverTestActivity extends Activity
{
    Broadcast mBroadcast = null;

    static Button btnStart;

    Button btnStop;

    Intent intent;

    String AUDIO_PATH = "/sdcard/Music/mtest2.mp3";


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music_receiver_test);


        btnStart = (Button) findViewById(R.id.btnPlayOrPause);
        btnStop = (Button) findViewById(R.id.btnStop);

        IntentFilter filter = new IntentFilter("music");

        mBroadcast = new Broadcast();
        registerReceiver(mBroadcast, filter);

    }

    @Override


    protected void onDestroy()
    {
        super.onDestroy();
        unregisterReceiver(mBroadcast);
    }


    public void clickHandle(View v)
    {
        switch (v.getId())
        {
            case R.id.btnPlayOrPause:
                intent = new Intent(MusicReceiverTestActivity.this, AudioService.class);

                Bundle bundle = new Bundle();
                bundle.putString("audioPath", AUDIO_PATH);

                intent.putExtras(bundle);
                startService(intent);
                break;
            case R.id.btnStop:
                if (intent != null)
                {
                    stopService(intent);
                }
                break;
        }
    }
}

